package com.chixing.config;

import com.chixing.interceptor.AutoIdempotentInterceptor;
import com.chixing.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//封装了@Component 将该类注入到Ioc容器中
public class MyInterceptorConfig implements WebMvcConfigurer {
    @Autowired // 到Ioc容器中找寻MyInterceptor对象
    private MyInterceptor myInterceptor;
    @Autowired
    private AutoIdempotentInterceptor autoldempotentInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns(要拦截的url)  ， 要以 / 开头
        //excludePathPatterns(不需要被拦截的url) ， 要以 / 开头
        registry.addInterceptor(myInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/product/**");


        registry.addInterceptor(autoldempotentInterceptor).addPathPatterns("/testmyorder/**");
    }
}
